package com.lx.nba.http;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;

public class HttpGet {

	private String url ;
	
	public HttpGet(String url ){
		
		this.url = url ;
		
	}
	
	public String sendGet(){
		
		if( this.url == null ){
			
			return null ;
			
		}
		
		StringBuffer content = new StringBuffer() ;
		
		BufferedReader in = null ;
		
		try {
			
			URL url = new URL(this.url) ;
			URLConnection connection = url.openConnection() ;

			in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8")) ;
			
			String line ;
			
			while( (line = in.readLine()) != null){
			
				content.append(line) ;
				
			}
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		return content.toString() ;
		
	}
	
	public String sendGet(String url){
		
		this.url = url ;
		
		return sendGet() ;
		
	}
	
	
}
